import React, { FC } from "react"
import { Typography } from "antd"
import { QuestionParagraphDefaultProps, QuestionParagraphPropsType } from "./interface"

const { Paragraph } = Typography

const QuestionParagraph: FC<QuestionParagraphPropsType> = (props: QuestionParagraphPropsType) => {
    const { text = "", isCenter = false } = { ...QuestionParagraphDefaultProps, ...props }

    // 实现换行
    const textList = text?.split("\n") // 根据换行符转为数组
    const content = textList.map((t, index) => {
        return (
            <span key={index}>
                {index > 0 && <br />}
                {t}
            </span>
        )
    })

    return <Paragraph style={{ textAlign: isCenter ? "center" : "start", marginBottom: "0" }}>{content}</Paragraph>
}

export default QuestionParagraph
